const mongoose = require('mongoose')

const Schema = mongoose.Schema
const Types = Schema.Types

const BookShelf = new Schema({
  id: Types.ObjectId,
  bookId: {
    type: Types.String,
    required: true,
    index: 1
  },
  userId: {
    type: Types.String,
    required: true,
    index: 1
  },
  bookName: {
    type: Types.String,
    required: true,
    index: 1
  },
  bookAuthor: {
    type: Types.String,
    index: 1
  },
  createTime: {
    type: Types.Date,
    default: Date.now,
    index: 1
  }
})

BookShelf.index({
  bookId: 1,
  userId: 1
}, {
  unique: true
})

module.exports = mongoose.model('BookShelf', BookShelf)
